<template>
<h2>房号新增</h2>
<table class="table table-bordered">
    <tr>
        <td>具体房号</td>
        <td>
            <input type="text" v-model="info.numname"/>
        </td>
    </tr>
    <tr>
        <td>房间楼层</td>
        <td>
            <input type="text" v-model="info.floor"/>楼
        </td>
    </tr>
    <tr>
        <td>状态</td>
        <td>
            <input type="radio" :value="true" v-model="info.state"/>启用
            <input type="radio" :value="false" v-model="info.state"/>禁用
        </td>
    </tr>
    <tr>
        <td colspan="2">
            <button class="btn btn-info" @click="Add">
                提交
            </button>
        </td>
    </tr>
</table>
</template>

<script setup lang="ts">
import {ref} from 'vue'
import axios from 'axios'
import { useRouter } from 'vue-router';
const router=useRouter()
const info=ref({
    numname:'',
    floor:'',
    state:true
})

const Add=()=>{
    axios.post('https://localhost:7173/api/Room/RoomNumAdd',{
        numname:info.value.numname,
        floor:info.value.floor,
        state:info.value.state
    })
    .then(res=>{
        if(res.data==-1){
            alert('该房号已存在请勿重复添加')
        }
        else if(res.data>0){
            alert('设置成功')
            router.push('/RoomNumShow')
        }
        else{
            alert('设置失败')
        }
    })
    .catch(err=>{
        console.log(err)
    })
}

</script>

